package com.etl.controller;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.etl.bean.User;
import com.etl.service.IUserService;

@Controller
@Scope(value="prototype")
@RequestMapping("/user")
public class UserController {
	@Resource
	private IUserService userService;

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login() throws Exception {
		return "login";
	}
	
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String index() throws Exception {
		return "index";
	}
	
	@RequestMapping(value="/checklogin",method=RequestMethod.POST)
	public String checkLogin(User user,Model model) throws Exception {
		if (userService.checkLogin(user.getUserAccount(), user.getUserPwd())) {
			model.addAttribute(user);
			return "index";
		}
		//model.addAttribute("retCode", 1);
		return "fail";
	}
	
	@RequestMapping(value="/toUserManager",method=RequestMethod.GET)
	public String toAddUser() throws Exception {
		return "userManager";
	}
}
